package com.dragon.repository.domain.dto;

import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Attendance;
import com.dragon.repository.entity.AttendanceChild;
import com.dragon.repository.entity.AttendanceLeave;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AttendanceDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Integer id;

    @ApiModelProperty(value = "用户id")
    private Integer adminId;

    @ApiModelProperty(value = "打卡状态：0未打卡 1.正常 2请假 4缺卡 3异常")
    private Integer attendanceType;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "配置id")
    private Integer arrangeId;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "请假时长（小时）")
    private String leaveDuration;

    @ApiModelProperty(value = "部门id")
    private Integer departmentId;

    @ApiModelProperty(value = "地址")
    private String address;

    @ApiModelProperty(value = "人员名称集合")
    private String adminNames;

    @ApiModelProperty(value = "打卡详细列表")
    private List<AttendanceChild> attendanceChildList;

    @ApiModelProperty(value = "打卡规则")
    private List<ArrangePeriodDTO> periodList;

    @ApiModelProperty(value = "打卡请假信息")
    private List<AttendanceLeaveDTO> attendanceLeave;

    public AttendanceDTO() {

    }

    public AttendanceDTO(Attendance entity) {
        BeanUtils.copyProperties(entity, this);
    }

    public static AttendanceDTO convert(Attendance entity) {
        return new AttendanceDTO(entity);
    }

    public static List<AttendanceDTO> convertList(List<Attendance> list) {
        List<AttendanceDTO> resultList = new ArrayList<>();
        for (Attendance entity : list) {
            resultList.add(new AttendanceDTO(entity));
        }
        return resultList;
    }
}
